<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of adm
 *
 * @author Dmitry
 */
class Controller_Adm extends Controller_Action {
  function index() {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
      $this->registry->get('view')->show('admmenu');
    }
    else
    {
      $this->registry->get('view')->show('admlogining');
    }
  }
  
  function check() {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
      $this->registry->get('view')->show('admmenu');
    }
    else
    {
      $this->registry->get('view')->set('login',$_POST['login']);
      $this->registry->get('view')->set('password',$_POST['pass']);
      if(empty ($_POST['login']) || empty ($_POST['pass']))
      {
        $this->registry->get('view')->set('message','Поля не повинні бути пустими!');
        $this->registry->get('view')->show('admlogining');
        return;
      }
      $adm = new Models_Adm();
      $user = $adm->isUserSet($_POST['login'], $_POST['pass']);
      if($user)
      {
        $this->registry->get('view')->show('admlogined');
      }
      else
      {
        $this->registry->get('view')->set('message','Ви ввели невірно ім\'я користувача або пароль!');
        $this->registry->get('view')->show('admlogining');
      }
    }
  }
  
  public function logout()
  {
    $adm = new Models_Adm();
    $adm->out();
    $this->registry->get('view')->show('admlogining');
  }
  
  public function menu()
  {
    $this->registry->get('view')->show('admmenu');
  }
  
  public function allArticles()
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
      $this->registry->get('view')->show('admallarticles');
    } else {
      $this->registry->get('view')->show('admlogining');
    }
  }
  
  public function addNewArticle()
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
      $this->registry->get('view')->show('admaddnewarticle');
    } else {
      $this->registry->get('view')->show('admlogining');
    }
  }
  
  public function articleAdded($arr)
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
        $this->registry->get('view')->show('admarticleadded');
    } else {
        $this->registry->get('view')->show('admlogining');
    }
  }

  public function edit($id)
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
        $this->registry->get('view')->set('id',$id);
        $this->registry->get('view')->show('admeditarticle');
    } else {
        $this->registry->get('view')->show('admlogining');
    }
  }

  public function articleEdited($arr,$id)
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
        $this->registry->get('view')->set('id',$id);
        $this->registry->get('view')->show('admarticleedited');
    } else {
        $this->registry->get('view')->show('admlogining');
    }
  }
  
  function allcomments()
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
        $this->registry->get('view')->show('admallcomments');
    } else {
        $this->registry->get('view')->show('admlogining');
    }
  }
  
  function editComment($id)
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
        $this->registry->get('view')->set('id',$id);
        $this->registry->get('view')->show('admeditcomment');
    } else {
        $this->registry->get('view')->show('admlogining');
    }
  }
  
  function activeComment($id)
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
        $this->registry->get('view')->set('id',$id);
        $content = new Models_Comment();
        $content->chengeActive($id);
        $this->registry->get('view')->show('admeditcomment');
    } else {
        $this->registry->get('view')->show('admlogining');
    }
  }
  
  function visibleComment($id)
  {
    $adm = new Models_Adm();
    if($adm->isAuth())
    {
        $this->registry->get('view')->set('id',$id);
        $content = new Models_Comment();
        $content->chengeVisible($id);
        $this->registry->get('view')->show('admeditcomment');
    } else {
        $this->registry->get('view')->show('admlogining');
    }
  }
}